Okay.
So today we are going to start off looking at one of the major concepts of scripting which is changing
properties.
Okay.
Now we know how to change properties ourselves.
But we're going to have a look at how to change them.
Um, in a script.
Now before we can actually change the properties, we need to understand something called referencing,
which is what we're going to have a look at today.
So add a script into your game.
Add a local script, not local script.
Sorry, a standard script into your game.
Delete.
Print.
Hello world.
We know what that means now and we're going to learn about referencing.
So what referencing in a script is is telling the script what object you are wanting to use.
So you need to do this before you can even start thinking about changing a property.
Because if I told you to change a property, you would have to know three things.
In order to do it, you would need to know what property I'm wanting you to change.
First you'd need to know.
So you need to know what?
Yeah, the what property I'm wanting you to change.
You need to know what object you're wanting to be looking at.
And third, what actually assign it to.
So what what what to give it.
What value should I give this property.
So we're looking at one of those today which is telling the script what object we're using, what we're
referring to.
Okay.
Um, and we can do this in two ways okay.
So we can start off looking at the first way.
So the first way we treat the explorer kind of like a family tree I think I explained this in the previous
section, but um, treat this as a family tree okay.
Let's add let's add a part in and we're going to we're going to try and reference this part here okay.
So this part is in the workspace and it's called part okay.
So um what we can do is we can go down the list of all of the parts parents until we get to the part.
So we start right up on top of the family tree.
We make our way down, we get to the great great grandparents, great grandparents, grandparents,
parents, and then the actual object itself.
Okay, so it's a good idea to treat this as a family tree.
So the very top ancestor, the very top person in this family tree is not actually the workspace.
It's the same as the workspace exists in the game.
Okay.
So to reference the game, um, you just write the word game like that's there.
That's as high up as you get.
Because then you can go to workspace, you can go to players, you can go to start, you can go to anything
okay.
So we first use game.
Then we want to go from the game to the workspace.
And we use the symbol dot for this.
So just a little dot like this here to go from the game to the workspace dot is used to represent a
member of basically.
So it's part of it.
The workspace is part of the game is a member of the game.
So we can say game dot workspace like it was appeared for us on on the second option there okay.
Game dot workspace from the workspace.
The part is a member of the workspace.
So we can write dot part like that there okay.
Now it's very very very very important that the capitalization.
So your capital letters and your lowercase letters are the exact same as what they are in the explorer
okay.
Workspace has to have a capital W and part has to be written exactly how it is for you.
So if you change the name given it a lowercase p, it needs to have a lowercase p in the script.
The reason for that is scripts are very specific on what they need.
If you misspell something once or you put a capital letter when it should be a lowercase letter, it
will throw an error, which basically means it won't do anything else.
It will just stop there because it doesn't know what you mean.
So you need to be incredibly specific when it comes to coding.
Okay, but this here is how you then reference this part.
So this bit of code here is telling the script we're wanting to use the part or do something with the
part okay.
And this is the first method to doing it.
Now this first method is great.
It's probably the simpler one to use.
Um, but it can be quite long winded because we looked at models and folders grouping objects.
Okay.
Often you will have to go through 5 or 6 groups of folders until you get to your actual object.
Take a game for example.
You might have your game dot workspace dot map one dot urban area dot um skyscraper dot floor 55 dot
um brown sofa for example.
You know, it can get very specific, very large maps.
So sometimes it is easier to use the second method.
I'm going to drop a line for that.
Um, we're just starting from the scripts position in the family tree.
So you can do this by just writing script like this here.
Okay.
So we start off with the script and we want to get from the script to the part.
Okay.
Now the script doesn't have any children.
So we can't go down the family tree to get to the part, so we can't go down.
Family trees don't work side to side, or at least they don't in Roblox studio.
So our only option is to go back up the family tree to go up the family tree.
You get to your parent.
Correct.
So you would say script dot parent.
Now, the reason why the parent is a member of the script is because the parent is a property.
This property here.
So we're actually referencing a property.
Not saying the parent is a member of the child.
That's not how it works.
It's a property.
Okay.
So that is referencing the script parent, which we know as the workspace.
Okay.
So now I've gotten to the workspace.
We've gotten we've we've risen up the family tree.
We can now go back down the family tree because the workspace is both a parent of the script and of
the part.
Sometimes you might have to go up a couple times and say script, parent, dot, parent or parent to
get to where you need to go to start going down back down the family tree.
Um, but for this case, we only need to do it once.
Okay.
From there we then reference a part normally.
So part as the part is a member of the workspace is part of the workspace.
Okay.
So there are two methods to referencing your objects.
Okay.
Now um this is something that you definitely will need some practice on okay.
Because it's absolutely fundamental to scripting.
So please, please make sure that you try something some out with ease.
Don't just watch a lecture and carry on.
Try some out.
Because, um.
You will find it quite difficult if you're not too confident on these, so make sure you are okay.
Now we've got one more thing before we finish off today's lecture, um, which is how to reference an
object with a space in its name.
Now, this sounds quite specific, but if I add a second part in okay, and I'm going to call this my
space part, it's got a space in it.
Okay.
Let's see what happens if I try to reference that part okay.
We can write game dot workspace.
Let's just write this and my space part okay.
You can probably see what's happening here okay.
All this is a certain color.
Um, meaning this is the game.
This is the workspace.
When we get to my space.
And then part is just white.
And if something is white in in Roblox studio, it means it's not kind of linked to anything.
It's kind of just on its own.
Um, most things aren't white.
They're different colors.
Red.
Blue is quite common as well.
Um, but white isn't really used too much.
Um, so basically it doesn't doesn't think this bit here is connected to this bit here, which is our
issue.
Okay.
So we have to use this a bit of a different way okay.
And that's involving strings.
So we need to tell the script that this space is actually part of the name.
And we're not separating these two words okay.
So put speech marks around this like this here.
And it will turn green okay.
They're the colors of your strings.
Then the only other thing we have to do is put square brackets around them both.
So put square brackets around this side, square brackets around this side.
And then just delete this dot after before workspace or after workspace.
And that's there is how you'd reference that part with a space.
Okay.
You get rid of the full stop.
You use a square brackets.
A bracket here is very important.
Use that brackets speech marks and then write the word or write whatever the string is.
Then another speech mark and close the brackets.
What that does is it tells us that, um, it's the value of um, my space part.
Okay.
So it's the value of this string.
So rather than it being one word, you have to kind of do it like this.
So I hope that just shows you how, um, when you're scripting, it's very important to not include
spaces in any names of your objects, because it comes a lot more difficult to code if they have spaces.
Okay.
So make sure when you're naming objects not to include any spaces, sometimes they will have spaces
or they will have other characters that you can't reference normally, which is fine.
You can use this method, but it's just to show you that, um, it's not as easy to to use it as this
here and um, writing in this form.
So writing like instead of writing my part like that there, writing my part like this.
This is called camel case.
So or technically you could write technically this here is camel case as well.
But the first letter doesn't matter too much.
It's more so the ones afterwards.
So every every new word there's no space.
But a capital letter is started with a new word.
Just so it's very clear what what it actually is that you've written down.
Otherwise can get a bit confusing to read it.
Okay, so that's just some good tips on how to make stuff more readable and how to make your live scripting
much easier.
Okay, so again, have some tries out with that.
Add some objects into your game, try referencing them.
Um, experiment with different objects, different parents or that kind of stuff.
And once you are okay with that, join me in the next lesson where we start to look at how we can apply
this and learn how to start changing some properties of the part.